Skip to content

fix: diff shows files as deleted when run from subdirectory - #120

Closed
jossephus wants to merge 1 commit into
jnsahaj:mainfrom
jossephus:fix/resolving-root-directory-for-diff
Closed

fix: diff shows files as deleted when run from subdirectory#120
jossephus wants to merge 1 commit into
jnsahaj:mainfrom
jossephus:fix/resolving-root-directory-for-diff

Conversation

@jossephus

@jossephus jossephus commented Jan 19, 2026

Copy link
Copy Markdown
Contributor

Running lumen diff from a subdirectory incorrectly showed modified files as deleted.

The issue was that file paths were resolved relative to the current working directory instead of the repository root. This fix adds repo_root() to VcsBackend and uses it to resolve paths correctly.

see before and after when running 'lumen diff' inside lumen/src

image image

Summary by CodeRabbit

  • Bug Fixes

    • Corrected file diff path resolution so new content is read relative to the repository root when running commands from subdirectories.
  • Tests

    • Added tests verifying file diff behavior when operating from repository subdirectories.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 19, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds a repo_root() accessor to the VcsBackend trait and implements it for Git and Jj backends. Updates get_new_content in the git diff command to resolve working-tree file reads relative to the repository root when available, and adds a test for reading from a subdirectory.

Changes

Cohort / File(s) Summary
VcsBackend Trait Extension
src/vcs/backend.rs
Added new repo_root(&self) -> Option<&Path> method to the VcsBackend trait.
Backend Implementations
src/vcs/git.rs, src/vcs/jj.rs
Implemented repo_root() in GitBackend (returns self.repo.workdir()) and JjBackend (returns Some(&self.workspace_path)).
Path Resolution in Diff Command
src/command/diff/git.rs
Modified get_new_content to join filename with backend.repo_root() when refs is WorkingTree, falling back to original path if no repo root; added test test_get_new_content_from_subdirectory.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • jnsahaj

Poem

🐰 I hop through branches, roots, and leaves,
I join your paths where the repository breathes,
From subdir shadows I fetch the new light,
No more wrong turns in the filesystem night,
Happy commits, and code that delights! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: resolving diff behavior when run from a subdirectory by using repository root paths instead of current working directory paths.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jossephus
jossephus force-pushed the fix/resolving-root-directory-for-diff branch from bf4b120 to 4b8df9f Compare January 19, 2026 20:42
@Straffern

Copy link
Copy Markdown

Might be related to: #110
I think I was also encountering this, when working on my fix and I think I also solved it.

@jossephus

Copy link
Copy Markdown
Contributor Author

oh sorry, i didnt see that. closing mine in favor of your PR since urs look complete. Thanks for letting me now

@jossephus jossephus closed this Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants